package jrobutt.room.level;

import jrobutt.*;
import jrobutt.room.ExplosionParticleEmitter;

import java.awt.*;
import java.awt.geom.*;

public class Enemy extends GameObject
{
    public float radius;
    public Vector2 facing_direction; 
    
    public float laser_length;
    public GameSprite laser_sprite;
    
    private int framer;
    private int laser_duration;
    
    public Enemy (float x, float y, Vector2 facing_direction, GameSprite sprite, GameSprite laser_sprite)
    {
        super(x, y, sprite);
        
        this.radius = 8.0f;
        
        this.facing_direction = facing_direction;
        
        this.laser_length = 96.0f; // half-way between 64 and 128
        this.laser_sprite = laser_sprite;
        
        this.framer = 0;
        this.laser_duration = (int)Settings.fps / 2;
    }
    
    public void update ()
    {
        super.update();
        framer++;
    }
    
    public void render (Graphics2D g)
    {
        AffineTransform prev_transform = g.getTransform();
        g.rotate(facing_direction.getAngle(), x, y);
        super.render(g);
        
        int substep = framer / laser_duration;
        if (substep % 2 == 0)
        {
            int N = 8;
            int subsub = substep / 2;
            int offset = subsub % N;
            float angle_increment = GameMath.TwoPi / (float)N;
            g.rotate(offset * angle_increment, x, y);
            
            int n = 4;
            angle_increment = GameMath.TwoPi / (float)n;
            for (int k=0; k<n; k++)
            {
                g.rotate(angle_increment, x, y);
                laser_sprite.renderAt(g, x+radius, y);
            }
        }
        g.setTransform(prev_transform);
    }
}
